﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PersonTask
{
    class Person
    {
        public const string FirstNameChangedMessage = "FirstName was changed";
        public const string LastNameChangedMessage = "LastName was changed";
        public const string GenderChangedMessage = "Gender was changed";
        public const string DateOfBirthChangedMessage = "DateOfBirth was changed";

        public string firstName = "";
        public string lastName = "";
        public string gender = "";
        public DateTime dateOfBirth = new DateTime();

        public string FirstName
        {
            get { return FirstName; }
            set
            {
                this.firstName = value;
                this.OnFirstNameChanged();
            }
        }
        public string LastName
        {
            get { return LastName; }
            set
            {
                this.lastName = value;
                this.OnLastNameChanged();
            }
        }
        public string Gender
        {
            get { return Gender; }
            set
            {
                this.gender = value;
                this.OnGenderChanged();
            }
        }
        public DateTime DateOfBirth
        {
            get { return DateOfBirth; }
            set
            {
                this.dateOfBirth = value;
                this.OnDateOfBirthChanged();
            }
        }

        public event EventHandler FirstNameChanged;
        public event EventHandler LastNameChanged;
        public event EventHandler GenderChanged;
        public event EventHandler DateOfBirthChanged;

        private void OnFirstNameChanged()
        {
            if (FirstNameChanged != null)
            {
                FirstNameChanged(this, new EventArgs());
            }
        }

        private void OnLastNameChanged()
        {
            if (LastNameChanged != null)
            {
                LastNameChanged(this, new EventArgs());
            }
        }

        private void OnGenderChanged()
        {
            if (GenderChanged != null)
            {
                GenderChanged(this, new EventArgs());
            }
        }

        private void OnDateOfBirthChanged()
        {
            if (DateOfBirthChanged != null)
            {
                DateOfBirthChanged(this, new EventArgs());
            }
        }

        public Person()
        {
            this.InitializeEventHandlers();
        }

        private void InitializeEventHandlers()
        {
            FirstNameChanged += new EventHandler(Person_FirstNameChanged);
            LastNameChanged += new EventHandler(Person_LastNameChanged);
            GenderChanged += new EventHandler(Person_GenderChanged);
            DateOfBirthChanged += new EventHandler(Person_DateOfBirthChanged);
        }

        void Person_DateOfBirthChanged(object sender, EventArgs e)
        {
            Console.WriteLine(DateOfBirthChangedMessage);
        }

        void Person_GenderChanged(object sender, EventArgs e)
        {
            Console.WriteLine(GenderChangedMessage);
        }

        void Person_LastNameChanged(object sender, EventArgs e)
        {
            Console.WriteLine(LastNameChangedMessage);
        }

        void Person_FirstNameChanged(object sender, EventArgs e)
        {
            Console.WriteLine(FirstNameChangedMessage);
        }
    }
}
